package com.zenika.zenbinding.sample.client;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.zenika.zenbinding.client.ZenBinder;
import com.zenika.zenbinding.client.model.BusinessObject;
import com.zenika.zenbinding.client.renderer.EnumListBoxRenderer;
import com.zenika.zenbinding.client.renderer.ListBoxRenderer;
import com.zenika.zenbinding.client.renderer.Renderer;
import com.zenika.zenbinding.client.renderer.TextBoxRenderer;
import com.zenika.zenbinding.sample.model.City;
import com.zenika.zenbinding.sample.model.LevelEnum;
import com.zenika.zenbinding.sample.model.Person;

public class TablePanel extends VerticalPanel {

	public TablePanel() {
		BusinessObject[] personnes = {
				new Person("Lefevre", "Jean", new City("Dax"), (Long) LevelEnum.MID_LEVEL.getKey()),
				new Person("Mondy", "Pierre", new City("Mont de Marsan"), (Long) LevelEnum.SENIOR.getKey()),
				new Person("Maccione", "Aldo", new City("Peymilou"), (Long) LevelEnum.JUNIOR.getKey()),
				new Person("Lamoureux", "Robert", new City("Bergerac"), (Long) LevelEnum.SENIOR.getKey()) };

		BusinessObject[] villes = { new City("Pau"), new City("Bidaray"), new City("Peymilou"), new City("Bergerac"),
				new City("Irouleguy"), new City("Mont de Marsan"), new City("Dax"), new City("Bayonne") };

		Renderer[] renderers = { new TextBoxRenderer("firstName"), new TextBoxRenderer("name"),
				new ListBoxRenderer("city", villes, "name"), new EnumListBoxRenderer("level", LevelEnum.getLevels()) };

		Label prenom = new Label("Prénom");
		prenom.setStyleName("header");
		Label nom = new Label("Nom");
		nom.setStyleName("header");
		Label age = new Label("Age");
		age.setStyleName("header");
		Label niveau = new Label("Niveau");
		age.setStyleName("header");

		Label[] headers = { prenom, nom, age, niveau };

		FlexTable table = new FlexTable();
		table.setBorderWidth(1);
		this.add(table);
		ZenBinder.bindTable(table, personnes, headers, renderers);

		// final List villesPossibles = new ArrayList();
		// final Person person = new Person();
		//
		// ListBox listBox = new ListBox();
		// ListBindingHandler handler = ZenBinder.createListBindingHandler(listBox, villesPossibles, "name");
		// ZenBinder.bindList(handler, person, "city");
	}

}
